package org.shushan.web.demo.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import org.shushan.framework.core.exception.ExceptionEnum;
import org.shushan.framework.core.resp.Result;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;


/**
 * (TUser)控制层
 * @author zhigang.li
 * @email 2429967859@qq.com
 * @since 2023-09-16 22:25:41
 */
@RestController
@Tag(name = "ExceptionTestController", description = "测试异常处理器")
@RequestMapping("exception")
public class ExceptionTestController {


    @GetMapping("runtimeException")
    public Result<Boolean> runtimeException() {
        throw new RuntimeException("1212");
    }

    @GetMapping("assertExcetion")
    public Result<Boolean> assertExcetion() {
        ExceptionEnum.UN_KNOWN_ERROR.isFalse(true);
        return Result.ok();
    }


    @GetMapping("validateParam")//todo 这里有问题
    public Result<Boolean> validateParam(@RequestParam @Valid @NotBlank(message = "111不能为空") String name) {
        return Result.ok();
    }


    @GetMapping("validateParamDto")//todo 这里有问题
    public Result<Boolean> validateParamDto(@Validated validateParamDto age) {
        return Result.ok();
    }

    static class validateParamDto {
        @NotBlank(message = "agedd不能为空")
        String  age;
    }


    @PostMapping("validateRequestBody")//todo这里有问题
    public Result<Boolean> validateRequestBody(@RequestBody @Validated ValidateRequestBody validateRequestBody ) {
        return Result.ok();
    }


    static class ValidateRequestBody{
        @NotBlank(message = "username不能为空")
        private String username;

    }

}

